package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hsp
 * @date 2021/5/24 10:56
 */
@RestController
@RequestMapping("shopping")
public class HomepageController {


    @Reference(timeout = 30000,retries = 0,check = false)
    IHomeService iHomeService;

    @GetMapping("homepage")
    @Anoymous
    public ResponseData homePage() {
        HomePageResponse homepage = iHomeService.homepage();

        if (homepage.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            ResponseData objectResponseData = new ResponseUtil<>().setData(homepage.getPanelContentItemDtos());
            return objectResponseData;
        }


        return new ResponseUtil<>().setErrorMsg(homepage.getMsg());
    }

}